CREATE PROCEDURE coreSchedulerSave
(
	@PK_ID			int output,
	@TaskName		nvarchar(500),
	@ExecuteNext	datetime,
	@Finished		bit,
	@Frequency		int,
	@Interval		int,
	@TimesRemaining	int,
	@Execute		nvarchar(500),
	@TaskExpires	bit,
	@ExpireTask		datetime
)
AS
BEGIN
	IF @PK_ID = -1
	BEGIN
		SET NOCOUNT ON;
		INSERT INTO ScheduledTasks (TaskName, ExecuteNext, Finished, Frequency, Interval, TimesRemaining, [Execute], TaskExpires, ExpireTask)
		VALUES (@TaskName, @ExecuteNext, @Finished, @Frequency, @Interval, @TimesRemaining, @Execute, @TaskExpires, @ExpireTask);
		SET NOCOUNT OFF;
		SELECT @PK_ID = @@IDENTITY;
	END
	ELSE
	BEGIN
		UPDATE ScheduledTasks SET
			TaskName		= @TaskName,
			ExecuteNext		= @ExecuteNext,
			Finished		= @Finished,
			Frequency		= @Frequency,
			Interval		= @Interval,
			TimesRemaining	= @TimesRemaining,
			[Execute]		= @Execute,
			TaskExpires		= @TaskExpires,
			ExpireTask		= @ExpireTask
		WHERE PK_ID = @PK_ID;
	END
END
